import store from "@/store";
import { Button, Form, Input } from "antd";
// import { useEffect } from "react";
import { useDispatch } from "react-redux";
import styles from "./index.module.less";
const Login: React.FC = () => {
  const dispatch = useDispatch();

  const onFinish = async (values: any) => {
    dispatch({
      type: "USER_LOGINR",
      payload: values,
      callback: () => {
        console.log(store.getState().userInfo.user);
        // setUser(store.getState().userInfo.user);
      },
    });
  };
  // useEffect(() => {
  //   store.subscribe(() => {
  //     console.log(";123123123", store.getState().userInfo.user);
  //   });
  // }, []);
  return (
    <div className={styles.login_container}>
      <div className={styles.wrap}>
        <div className={[styles.first_title, "enter_1"].join(" ")}>
          欢迎使用{store.getState().userInfo.user.token}
        </div>
        <div className={[styles.title, "enter_2"].join(" ")}>
          React+vite后台管理系统
        </div>
        <div className={styles.form_wrap}>
          <Form
            name="basic"
            labelWrap
            onFinish={onFinish}
            layout="vertical"
            style={{ maxWidth: 600 }}
            initialValues={{ remember: true }}
            autoComplete="off"
          >
            <Form.Item
              className="enter_3"
              label="用户名"
              name="username"
              rules={[{ required: true, message: "请输入用户名" }]}
            >
              <Input placeholder="请输入用户名：默认admin" />
            </Form.Item>

            <Form.Item
              label="密码"
              name="password"
              className="enter_4"
              rules={[{ required: true, message: "请输入密码" }]}
            >
              <Input.Password placeholder="请输入密码：默认admin" />
            </Form.Item>

            <Form.Item style={{ textAlign: "center" }} className="enter_5">
              <Button
                type="primary"
                className={styles.btn_style}
                size="large"
                htmlType="submit"
              >
                立即登录
              </Button>
            </Form.Item>
          </Form>
        </div>
      </div>
    </div>
  );
};

export default Login;
